<!DOCTYPE HTML>
<html>

<head>
    <title>Easy-JTest</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link href="/static/images/favicon.ico" rel="shortcut icon">
    <script type="text/javascript" src="/static/jquery/jquery-3.6.0.min.js"></script>
    <style>
        nav {
            width: 100%;
            margin-top: 140px;
        }

        nav p {
            width: 750px;
            height: 35px;
            line-height: 35px;
            margin: 8px auto;
        }

        .logo {
            text-align: center;
        }

        .logo img {
            width: 215px;
            height: 110px;
        }

        .search {
            width: 750px;
            height: 50px;
            margin: auto;
            display: flex;
            justify-content: center;
            align-content: center;
            min-width: 750px;
            position: relative;
        }

        input {
            width: 550px;
            height: 40px;
            border-right: none;
            border-bottom-left-radius: 10px;
            border-top-left-radius: 10px;
            border-color: #f5f5f5;
            outline: none;
        }

        input:hover {
            box-shadow: 2px 2px 2px #ccc;
        }

        input:focus {
            border-color: rgb(78, 110, 242);
        }

        .search span {
            position: absolute;
            font-size: 23px;
            top: 10px;
            right: 170px;
        }

        .search span:hover {
            color: rgb(78, 110, 242);
        }

        button {
            width: 100px;
            height: 44px;
            background-color: rgb(78, 110, 242);
            border-bottom-right-radius: 10px;
            border-top-right-radius: 10px;
            border-color: rgb(78, 110, 242);
            color: white;
            font-size: 14px;
        }

        #ranking_list {
            width: 750px;
            height: 100%;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            margin: auto;
            margin-inside: 18px auto;
        }

        input.red {
            background: #ffe9e8;
        }

        /*a{*/
        /*    text-decoration:none;*/
        /*}*/
        a:hover {
            color: #2775b6;
        }

        #beanName {
            width: 750px;
            height: 50px;
            margin: auto;
            display: flex;
            justify-content: left;
            align-content: flex-start;
            min-width: 750px;
            position: relative;
            left: 50px;
            top: 15px;
            display: none;
        }
    </style>
    <script type="text/javascript">
        //闪动
        function shake(ele, cls, times) {
            ele.css("border", "1px solid #ef4136");
            var i = 0, t = false, o = ele.attr("class") + " ", c = "", times = times || 2;
            if (t) return;
            t = setInterval(function () {
                i++;
                c = i % 2 ? o + cls : o;
                ele.attr("class", c);
                if (i == 2 * times) {
                    clearInterval(t);
                    -
                        ele.removeClass(cls);
                    ele.css("border", "");
                }
            }, 200);
        };

        $(document).ready(function () {
            $("#search_click").click(function () {
                var search_txt = $("#search_txt").val();
                if (search_txt == "") {
                    shake($("#search_txt"), "red", 3);
                } else {
                    $.ajax({
                        url: "/search",
                        type: "POST",
                        dataType: "json",
                        data: {"beanName": search_txt},
                        beforeSend: function (xhr) {
                            $("#bang").empty();
                            $("#beanName").html("");
                            $("#bang").attr("style", "display:none;");
                            $("#ranking_list").attr("style", "display:none;");
                            console.log("before send");
                        },
                        success: function (data) {
                            console.log(data);
                            if (data.code == "404") {
                                $("#ranking_list").attr("style", "display:'';");
                                var message = "Not find java bean name is <span style=\"color: red; font-weight: bold;\">" + data.message + "</span> in spring container!Please check!";
                                $("#beanName").html(message);
                                $('#beanName').show();
                            } else if (data.code == 200) {
                                $("#ranking_list").attr("style", "display:'';");
                                $("#bang").attr("style", "display:'';height: 450px;border: 2px rgb(78, 110, 242) solid; overflow: auto; padding-left:10px; right: 170px;");
                                // $("#beanName").html(data.data.beanName);
                                var beanInfos = data.data.methods;
                                if (beanInfos == null || beanInfos.length === 0) {
                                    $("#bang").append("<p>" + "<span style=\"color: red; font-weight: bold;\">" + data.data.beanName + "</span>" + "&nbsp;&nbsp;not find method!</p>");
                                } else {
                                    var html = "";
                                    $.each(beanInfos, function (index, obj) {  //index:索引obj:循环的每个元素
                                        var parameter = obj.parameterList;
                                        html += "<a href='' target='_blank' onclick=\"return false;\"> " + obj.methodName + "(";
                                        if (parameter != null || parameter.length != 0) {
                                            $.each(parameter, function (index1, obj1) {
                                                html += obj1.parameterTypeStr + " " + obj1.parameterName;
                                                if (index1 <= parameter.length - 2) {
                                                    html += ",";
                                                }
                                            });
                                            var classData = {};
                                            classData.beanName = data.data.beanName;
                                            classData.methodName = obj.methodName;
                                            classData.parameter = parameter;
                                            console.log(JSON.stringify(classData))
                                            html += ") <input type='hidden'  value='" + JSON.stringify(classData) + "'> </a>";
                                            html += "<br/><br/>";
                                        }

                                    });
                                    $("#bang").append(html);

                                }

                            }
                        },
                        error: function () {
                            console.log("请求error");
                        },
                        complete: function (xhr) {
                            console.log("complete");
                            console.log(xhr);
                        },
                        timeout: function () {
                            console.log("response time out!");
                        }
                    })
                }


            });

        });

        $(function () {
            $("#bang").on("click", "a", function () {
                var classData = $(this).children("input").val();

                var url = "/middleman";
                var params = {
                    classData: classData
                };

                // 将参数对象转换为查询字符串
                var queryString = Object.keys(params)
                    .map(key => key + '=' + encodeURIComponent(params[key]))
                    .join('&');

                // 构建完整的URL
                var fullUrl = url + '?' + queryString;

                // 使用window.open()方法打开新页面
                window.open(fullUrl, '_blank'); // '_blank'表示在新标签页中打开

            });
        });


    </script>
</head>

<body>


<!-- Main -->
<div id="main">
    <nav>
        <div class="logo">
            <h2 class="Hero-title"><i class="icon fas fa-exclamation-triangle"></i> Easy JTest</h2>
        </div>
        <div class="search-container">
            <div class="search">
                <input id="search_txt" type="text" placeholder="Please enter java bean name! Make java test simple!">
                <button id="search_click">search</button>
            </div>
            <p id="beanName" style="color: #15559a;font-size: 16px"> xxxxxx</p>
        </div>
    </nav>
</div>
</br>
</br>

<div id="ranking_list" style="display:none;">
    <div id="bang" style="display:none;">

    </div>
</div>


</body>

</html>